//
//  NoticeViewController.m
//  gpos_app
//
//  Created by 崔航飞 on 2018/8/25.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "NoticeViewController.h"
#import "Masonry.h"
#import "NoticeTableViewCell.h"
#import "GPosAPI.h"
#import "SVProgressHUD.h"
#import "MerChantModel.h"
#import "MJRefresh.h"
#import "XMRegisterViewController.h"
#import "WKProgressHUD.h"
@interface NoticeViewController ()<UITableViewDataSource,UITableViewDelegate,NoticeTableViewCellDelegate,UIGestureRecognizerDelegate>
@property (nonatomic,strong) UIView *backgroundViews;
@property (nonatomic,strong) UITableView *mainTable;
@property (nonatomic,strong) NSMutableArray *dataArr;
@property (nonatomic,assign) NSInteger userId;
@property (nonatomic,assign) NSInteger pagesize;
@property (nonatomic,assign) NSInteger page;
@property (nonatomic,strong) NSDictionary *dic;
@property (nonatomic,strong) NSMutableArray *AllArray;
@property (nonatomic,strong) UIView *bigView;
@property (nonatomic,strong) UIView *smailView;
@property (nonatomic,strong) UIButton *cancellBtn;
@property (nonatomic,strong) UIButton *tureBtn;
@property (nonatomic,assign) NSIndexPath *currentIndexPath;
@property (assign,nonatomic) NSInteger ids;
@property (nonatomic,strong) UILabel *lab1;
@property (nonatomic,strong) UILabel *lab2;
@property (nonatomic,strong) NSDictionary *dics;
@property (nonatomic,strong) NSMutableArray *newsAddArr;
@property (nonatomic,strong) WKProgressHUD *hud;
@property (nonatomic,strong) UIImageView *ZWXXImage;
@end

@implementation NoticeViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden=NO;
    //去掉返回的文字
    self.navigationController.navigationBar.topItem.title = @"";
    self.navigationItem.title=@"消息";
    
    
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
}
-(void)viewDidLayoutSubviews{
    
    [super viewDidLayoutSubviews];
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    self.navigationController.navigationBar.backgroundColor=[UIColor whiteColor];
    self.navigationController.navigationBar.tintColor=[UIColor blackColor];
    self.dataArr=[NSMutableArray new];
    self.AllArray=[NSMutableArray new];
    self.newsAddArr=[NSMutableArray new];
    self.page=1;
    self.pagesize=10;
    self.userId=[[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] integerValue];
    self.dic=[NSDictionary dictionaryWithObjectsAndKeys:@(self.page),@"page",@(self.pagesize),@"pageSize",@(self.userId),@"userId", nil];
    __weak typeof(self) weakSelf = self;
    
    [GPosAPI requestNoticeWithParams:self.dic andCallback:^(id obj) {
        if (obj==nil)
        {
   
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            [weakSelf initUI];
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                weakSelf.dataArr=[obj objectForKey:@"data"];
                NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                for (data in weakSelf.dataArr)
                {
                    
                    MerChantModel *group=[[MerChantModel alloc] init];
                    group.address=[data objectForKey:@"created"];//代表Created
                    group.type=[data objectForKey:@"type"];
                    group.name=[data objectForKey:@"title"];//代表title
                    group.ids=[[data objectForKey:@"id"] integerValue];
                    group.phone=[data objectForKey:@"content"];
                    
                    [weakSelf.AllArray addObject:group];
                }
                [weakSelf initUI];
                [weakSelf.mainTable reloadData];
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
            
                [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
               XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                 [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
            else{
                
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                [weakSelf initUI];
            }
        }
        
    }];
}
-(void)initUI{
    
    self.backgroundViews=[[UIView alloc] init];
    self.backgroundViews.backgroundColor=[UIColor colorWithWhite:0.94 alpha:1];
    [self.view addSubview:self.backgroundViews];
    [self.backgroundViews mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view.mas_top).offset(kNavbarHeight);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@(KmainScreenHeiht - kNavbarHeight - kBottomSafeHeight));
        
    }];
    
    self.mainTable = [[UITableView alloc] init];
    self.mainTable.backgroundColor = [UIColor whiteColor];
    self.mainTable.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.mainTable.delegate=self;
    self.mainTable.dataSource=self;
    self.mainTable.showsVerticalScrollIndicator = NO;
    self.mainTable.alwaysBounceVertical = YES;
    self.mainTable.mj_footer=[MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreShopss)];
    
    self.mainTable.mj_header=[MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewShopss)];
    [self.mainTable.mj_header beginRefreshing];
    [self.backgroundViews addSubview:self.mainTable];
    
    [self.mainTable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.backgroundViews.mas_top).offset(10);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.backgroundViews.mas_bottom);
    }];
    
//    self.ZWXXImage=[[UIImageView alloc] init];
//    self.ZWXXImage.image=[UIImage imageNamed:@"icon_zwxiaoxi"];
//    self.ZWXXImage.hidden=YES;
//    [self.mainTable addSubview:self.ZWXXImage];
//    [self.ZWXXImage mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.backgroundViews.mas_top).offset(120);
//    make.left.equalTo(self.backgroundViews.mas_left).offset(KmainScreenWidth/2-50);
//    }];
    
}
//下拉刷新
-(void)loadNewShopss{
    __weak typeof(self) weakSelf = self;
    
    self.dataArr=[NSMutableArray new];
    self.AllArray=[NSMutableArray new];
    self.page=1;
    self.pagesize=10;
    self.userId=[[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] integerValue];
    self.dic=[NSDictionary dictionaryWithObjectsAndKeys:@(self.page),@"page",@(self.pagesize),@"pageSize",@(self.userId),@"userId", nil];
    
    [GPosAPI requestNoticeWithParams:self.dic andCallback:^(id obj) {
        if (obj==nil)
        {
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                weakSelf.dataArr=[obj objectForKey:@"data"];
                NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                for (data in weakSelf.dataArr)
                {
                    
                    MerChantModel *group=[[MerChantModel alloc] init];
                    group.address=[data objectForKey:@"created"];//代表Created
                    group.type=[data objectForKey:@"type"];
                    group.name=[data objectForKey:@"title"];//代表title
                    group.ids=[[data objectForKey:@"id"] integerValue];
                    group.phone=[data objectForKey:@"content"];
                    
                    [weakSelf.AllArray addObject:group];
                }
                
                [weakSelf.mainTable reloadData];
                [weakSelf.mainTable.mj_header endRefreshing];
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
               [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
            else{
                
                
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
        }
        
    }];
    
}
//上拉加载
-(void)loadMoreShopss{
    
    __weak typeof(self) weakSelf = self;
    self.page++;
    NSLog(@"%ld",self.page);
    self.dic=[NSDictionary dictionaryWithObjectsAndKeys:@(self.page),@"page",@(self.pagesize),@"pageSize",@(self.userId),@"userId", nil];
    
    
    [GPosAPI requestNoticeWithParams:weakSelf.dic andCallback:^(id obj) {
        if (obj==nil)
        {
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                weakSelf.newsAddArr=[obj objectForKey:@"data"];
                NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                for (data in weakSelf.newsAddArr)
                {
                    
                    MerChantModel *group=[[MerChantModel alloc] init];
                    group.address=[data objectForKey:@"created"];//代表Created
                    group.type=[data objectForKey:@"type"];
                    group.name=[data objectForKey:@"title"];//代表title
                    group.ids=[[data objectForKey:@"id"] integerValue];
                    group.phone=[data objectForKey:@"content"];
                    
                    [weakSelf.AllArray addObject:group];
                }
                [weakSelf.dataArr addObjectsFromArray:weakSelf.newsAddArr];
                
                [weakSelf.mainTable reloadData];
                [weakSelf.mainTable.mj_footer endRefreshing];
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
               [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
            else{
                
                
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
        }
        
    }];
    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArr.count;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 70;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NoticeTableViewCell *cell=[[[NSBundle mainBundle] loadNibNamed:@"NoticeTableViewCell" owner:self options:nil] firstObject];
    cell.delegate=self;
    cell.mode=self.AllArray[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
//删除消息
-(void)deleCell:(NoticeTableViewCell *)cells withButton:(UIButton *)btn{
    
    //获取准确的indexPath
    self.currentIndexPath = [self.mainTable indexPathForCell:cells];
    MerChantModel *mo=self.AllArray[self.currentIndexPath.row];
    self.ids=mo.ids;
   
    [self deleSmallView];
}
//点击是设置为已读消息
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    NSLog(@"+++++++=%ld",indexPath.row);
//    NSLog(@"%@",self.AllArray);
    MerChantModel *mos=self.AllArray[indexPath.row];
    if ([mos.type isEqualToString:@"0"]) {
    
    NSInteger userId=[[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] integerValue];
    NSString *type=@"1";//2代表删除
    self.dics=[NSDictionary dictionaryWithObjectsAndKeys:@(userId),@"userId",type,@"type",@(mos.ids),@"messageId", nil];
        
    [GPosAPI requestDelegateNoticeWithParams:self.dics andCallback:^(id obj) {
        if (obj==nil)
        {
          
            NSLog(@"请求失败,请检查您的网络状态");
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                NSLog(@"成功");
            
                
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
            else{
            
                NSLog(@"请求失败");
            }
        }
    }];
}
    [self readloneyPopView:mos];

    
}
//删除的时候弹出的视图
-(void)deleSmallView{
    
    //弹出提示框
    self.bigView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    self.bigView.backgroundColor=[[UIColor blackColor]colorWithAlphaComponent:0.3];
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backviewsmallkes:)];
    tap.delegate=self;
    [self.bigView addGestureRecognizer:tap];
    
    self.smailView=[[UIView alloc] initWithFrame:CGRectMake(35, [UIScreen mainScreen].bounds.size.height/2-90, [UIScreen mainScreen].bounds.size.width-70, 180)];
    self.smailView.backgroundColor=[UIColor whiteColor];
    self.smailView.layer.cornerRadius=4;
    self.smailView.userInteractionEnabled=YES;
    
    UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(0, 129, self.smailView.frame.size.width, 1)];
    lineView.backgroundColor=[UIColor grayColor];
    lineView.alpha=0.1;
    [self.smailView addSubview:lineView];
    
    UIView *HlineView=[[UIView alloc] initWithFrame:CGRectMake(self.smailView.frame.size.width/2-0.5, CGRectGetMaxY(lineView.frame), 1, 50)];
    HlineView.backgroundColor=[UIColor grayColor];
    HlineView.alpha=0.1;
    [self.smailView addSubview:HlineView];
    
    UILabel *smalLab=[[UILabel alloc] initWithFrame:CGRectMake(0, 55, self.smailView.frame.size.width, 20)];
    smalLab.text=@"确定删除本条消息?";
    smalLab.textAlignment = NSTextAlignmentCenter;
    [self.smailView addSubview:smalLab];
    
    self.cancellBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    self.cancellBtn.frame=CGRectMake(0, CGRectGetMaxY(lineView.frame), self.smailView.frame.size.width/2, 50);
    
    
    [self.cancellBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    self.cancellBtn.titleLabel.font=[UIFont boldSystemFontOfSize:15];
    
    
    self.tureBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    self.tureBtn.frame=CGRectMake(CGRectGetMaxX(HlineView.frame), CGRectGetMaxY(lineView.frame), self.smailView.frame.size.width/2, 50);
    
    [self.tureBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    self.tureBtn.titleLabel.font=[UIFont boldSystemFontOfSize:15];
    [self.cancellBtn setTitle:@"取消" forState:UIControlStateNormal];
    [self.cancellBtn addTarget:self action:@selector(QXBtns) forControlEvents:UIControlEventTouchUpInside];
    [self.tureBtn setTitle:@"确定" forState:UIControlStateNormal];
    [self.tureBtn addTarget:self action:@selector(OKBtns) forControlEvents:UIControlEventTouchUpInside];
    [self.smailView addSubview:self.cancellBtn];
    [self.smailView addSubview:self.tureBtn];
    [self.bigView addSubview:self.smailView];
    //加到全屏
    [[UIApplication sharedApplication].keyWindow addSubview:self.bigView];
    
}
-(void)QXBtns{
    
    [UIView animateWithDuration:0.6 animations:^{
        
    } completion:^(BOOL finished) {
        
        self.bigView.hidden=YES;
        
    }];
    
}
//确定的点击事件
-(void)OKBtns{
   
    self.bigView.hidden=YES;
    __weak typeof(self) weakSelf = self;
    NSInteger userId=[[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] integerValue];
    NSString *type=@"2";//2代表删除
    
    NSDictionary *dics=[NSDictionary dictionaryWithObjectsAndKeys:@(userId),@"userId",type,@"type",@(self.ids),@"messageId", nil];
    [GPosAPI requestDelegateNoticeWithParams:dics andCallback:^(id obj) {
        if (obj==nil)
        {
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
           
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                [weakSelf.mainTable beginUpdates];
                //删除
                [weakSelf.dataArr removeObjectAtIndex:weakSelf.currentIndexPath.row];
                
                //这里不能直接使用cellForRowAtIndexPath代理方法中传入的indexPath，因为在删除一次后如果继续向下删除，indexPath会因为没有刷新而产生错误
                [weakSelf.mainTable deleteRowsAtIndexPaths:@[weakSelf.currentIndexPath] withRowAnimation:UITableViewRowAnimationFade];
                [weakSelf.mainTable endUpdates];
                [self loadNewShopss];//重新加载一下数据
                NSLog(@"%@",weakSelf.dataArr);
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
            else{
                
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
               
            }
        }
    }];
  
}
-(void)backviewsmallkes:(UITapGestureRecognizer *)tp{
    
    [UIView animateWithDuration:0.6 animations:^{
        
    } completion:^(BOOL finished) {
        
        self.bigView.hidden=YES;
        
    }];
    
}
//手势的代理(点击大的视图，防止触发小的视图)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    
    if ([touch.view isDescendantOfView:self.smailView]) {
        return NO;
    }
    return YES;
}
//点击cell已读弹出的视图
-(void)readloneyPopView:(MerChantModel *)mo{
    
    
    //弹出提示框
    self.bigView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    self.bigView.backgroundColor=[[UIColor blackColor]colorWithAlphaComponent:0.3];
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backviewsmallkeses:)];
    tap.delegate=self;
    [self.bigView addGestureRecognizer:tap];
    
    self.smailView=[[UIView alloc] initWithFrame:CGRectMake(35, [UIScreen mainScreen].bounds.size.height/2-60, [UIScreen mainScreen].bounds.size.width-70, 120)];
    self.smailView.backgroundColor=[UIColor whiteColor];
    self.smailView.layer.cornerRadius=8;
    self.smailView.userInteractionEnabled=YES;
    
    UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(0, self.smailView.frame.size.height/2-20, self.smailView.frame.size.width, 2)];
    lineView.backgroundColor=[UIColor blueColor];
    UIButton *dismissBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    dismissBtn.userInteractionEnabled=YES;
    [dismissBtn addTarget:self action:@selector(dismisView) forControlEvents:UIControlEventTouchUpInside];
    [dismissBtn setImage:[UIImage imageNamed:@"icon_guanbi"] forState:UIControlStateNormal];
    dismissBtn.frame=CGRectMake(20, 11, 20, 20);
    self.lab1=[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(dismissBtn.frame)+15, 5, self.smailView.frame.size.width-100, 28)];
    self.lab1.textAlignment=NSTextAlignmentCenter;

    self.lab1.font=[UIFont systemFontOfSize:15];
    self.lab2=[[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(lineView.frame)+10, self.smailView.frame.size.width-40, 60)];
    self.lab2.textAlignment=NSTextAlignmentCenter;
  
    self.lab2.numberOfLines=3;
    self.lab2.font=[UIFont systemFontOfSize:13];
    self.lab1.text=[NSString stringWithFormat:@"%@",mo.name];
    self.lab2.text=[NSString stringWithFormat:@"    %@",mo.phone];
    [self.smailView addSubview:self.lab2];
    [self.smailView addSubview:self.lab1];
    [self.smailView addSubview:dismissBtn];
    [self.smailView addSubview:lineView];
    [self.bigView addSubview:self.smailView];
    
    //加到全屏
    [[UIApplication sharedApplication].keyWindow addSubview:self.bigView];

    
}
-(void)dismisView{
    __weak typeof(self) weakSelf = self;
    self.bigView.hidden=YES;
    self.dataArr=[NSMutableArray new];
    self.AllArray=[NSMutableArray new];
    self.page=1;
    self.pagesize=10;
    self.userId=[[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] integerValue];
    self.dic=[NSDictionary dictionaryWithObjectsAndKeys:@(self.page),@"page",@(self.pagesize),@"pageSize",@(self.userId),@"userId", nil];
    [SVProgressHUD showWithStatus:@"加载中"];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    [GPosAPI requestNoticeWithParams:self.dic andCallback:^(id obj) {
        if (obj==nil)
        {
            [SVProgressHUD dismiss];
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
           
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                [SVProgressHUD dismiss];
                weakSelf.dataArr=[obj objectForKey:@"data"];
                NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                for (data in weakSelf.dataArr)
                {
                    
                    MerChantModel *group=[[MerChantModel alloc] init];
                    group.address=[data objectForKey:@"created"];//代表Created
                    group.type=[data objectForKey:@"type"];
                    group.name=[data objectForKey:@"title"];//代表title
                    group.ids=[[data objectForKey:@"id"] integerValue];
                    group.phone=[data objectForKey:@"content"];
                    
                    [weakSelf.AllArray addObject:group];
                }
               
                [weakSelf.mainTable reloadData];
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                [SVProgressHUD dismiss];
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
            else{
                
                [SVProgressHUD dismiss];
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
              
            }
        }
        
    }];
   
}
-(void)backviewsmallkeses:(UITapGestureRecognizer *)tp{
    __weak typeof(self) weakSelf = self;
    self.bigView.hidden=YES;
    self.dataArr=[NSMutableArray new];
    self.AllArray=[NSMutableArray new];
    self.page=1;
    self.pagesize=10;
    self.userId=[[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"] integerValue];
    self.dic=[NSDictionary dictionaryWithObjectsAndKeys:@(self.page),@"page",@(self.pagesize),@"pageSize",@(self.userId),@"userId", nil];
    [SVProgressHUD showWithStatus:@"加载中"];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    [GPosAPI requestNoticeWithParams:self.dic andCallback:^(id obj) {
        if (obj==nil)
        {
            [SVProgressHUD dismiss];
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                [SVProgressHUD dismiss];
                weakSelf.dataArr=[obj objectForKey:@"data"];
                NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                for (data in weakSelf.dataArr)
                {
                    
                    MerChantModel *group=[[MerChantModel alloc] init];
                    group.address=[data objectForKey:@"created"];//代表Created
                    group.type=[data objectForKey:@"type"];
                    group.name=[data objectForKey:@"title"];//代表title
                    group.ids=[[data objectForKey:@"id"] integerValue];
                    group.phone=[data objectForKey:@"content"];
                    
                    [weakSelf.AllArray addObject:group];
                }
                
                [weakSelf.mainTable reloadData];
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                [SVProgressHUD dismiss];
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
            else{
                
                [SVProgressHUD dismiss];
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
        }
        
    }];
    
}
#pragma mark - TableView 占位图

- (UIImage *)xy_noDataViewImage {
    return [UIImage imageNamed:@"icon_zwxiaoxi"];
}

- (NSString *)xy_noDataViewMessage {
    return @"暂无消息哦";
}

- (UIColor *)xy_noDataViewMessageColor {
    return [UIColor blackColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
